<?php


namespace app\controller\archives;
require_once __DIR__.'/../../common/AuthController.php';
use app\common\AuthController;


/**
 * 商家
 */
class Merchant extends AuthController
{   


    /**
     * 初始化操作
     */
    public function init()
    {

    }
	

    /**
     * 获取商家列表
     */
	public function api_archives_merchant_getList($msg)
    {   
        global $db;
        $page = isset($msg['data']['page'])?$msg['data']['page']:1;
        $rows = isset($msg['data']['rows'])?$msg['data']['rows']:15;
        $limit = ($page-1)*$rows.','.$rows;
        $data = [
           'id' => isset($msg['data']['id'])?$msg['data']['id']:'',
           'name' => isset($msg['data']['name'])?$msg['data']['name']:'',
           'linkman' => isset($msg['data']['linkman'])?$msg['data']['linkman']:'',
           'mobile' => isset($msg['data']['mobile'])?$msg['data']['mobile']:'',
           'trade_name' => isset($msg['data']['trade_name'])?$msg['data']['trade_name']:'',
           'region_name' => isset($msg['data']['region_name'])?$msg['data']['region_name']:'',
        ];
        $where = 'a.country_id = 100000 AND a.status = 0';
        if(!empty($data['name'])){
            $where .= " AND a.name LIKE '%".$data['name']."%'";
        }
        if(!empty($data['linkman'])){
            $where .= " AND a.linkman LIKE '%".$data['linkman']."%'";
        }
        if(!empty($data['mobile'])){
            $where .= " AND a.mobile LIKE '%".$data['mobile']."%'";
        }
        if(!empty($data['id'])){
            $where .= " AND a.id =".$data['id'];
        }
        if(!empty($data['trade_name'])){
            $where .= " AND b.name LIKE '%".$data['trade_name']."%'";
        }
        if(!empty($data['region_name'])){
            $where .= " AND a.region_name LIKE '%".$data['region_name']."%'";
        }
        $res =  $db->query("SELECT a.id,a.name,a.region_name,a.address,a.linkman,a.mobile,a.created_at,a.ad_income,a.balance,a.status,b.name as trade_name1,a.reject_trade_ids,a.openid,a.reject_trade_name as trade_name from merchant_expand as a left join trade as b on a.main_category_id = b.id WHERE ".$where ." limit ".$limit);
        $count =  $db->query("SELECT count(*) as count from merchant_expand as a left join trade as b on a.main_category_id = b.id WHERE ".$where);
		return $this->outMessage(10000,'获取成功',$res,'success',$count[0]['count']);
	}




 

}
